package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : 李亚红
 * @Date: 2025/8/4 12:59
 * @DESC:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @RequestMapping("/findAll")
    public List<User> findAll(){
        List<User> all = userService.findAll();
        return all;
    }

    @RequestMapping("/insert")
    public String insert(User user){
        userService.insert(user);
        return "success";
    }

    @RequestMapping("/deleteById")
    public String delete(Integer id){
        userService.delete(id);
        return "success";
    }

    @RequestMapping("/updateById")
    public String update(User user){
        userService.update(user);
        return "success";
    }

    @RequestMapping("/findById")
    public User findById(Integer id){
        return userService.findById(id);
    }


}
